@extends('layout.master')

@section('title','康侣后台管理')

@section('css')
    @parent
    <link href="{{ asset('plugins/bower_components/summernote/dist/summernote.css') }}" rel="stylesheet"/>
    <!-- animation CSS -->
    <link href="{{ asset('css/animate.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/icheck/skins/all.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/bootstrap-switch/bootstrap-switch.min.css') }}" rel="stylesheet">
@endsection
@section('main')
    <div class="row">
        <div class="col-lg-12 col-md-12">
            <div class="white-box">
                <div class="row button">
                    <div class="col-md-4 col-sm-12">
                        <div class="form-group">
                            <div class="col-lg-10 col-sm-10 col-xs-10">
                                <button class="btn btn-block btn-info waves-effect" id="post">发帖</button>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-4 col-sm-12">
                        <div class="form-group">
                            <div class="col-lg-10 col-sm-10 col-xs-10">
                                <button class="btn btn-block btn-primary waves-effect" id="push">推送</button>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-4 col-sm-12">
                        <div class="form-group">
                            <div class="col-lg-10 col-sm-10 col-xs-10">
                                <button class="btn btn-block btn-success waves-effect" id="store">发帖</button>
                            </div>
                        </div>
                    </div>


                </div>
                <div id="post-booter">
                    <div class="row">
                        <div class="col-sm-12">
                            <textarea ></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <button class="fcbtn btn btn-success btn-outline btn-1e waves-effect">编辑完毕1</button>
                    </div>
                </div>
                <div id="push-booter">
                    <div class="row">
                        <div class="col-sm-12">
                            <textarea style="height: 150px; width: 100%;overflow:auto;"name="contents" id="contents"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <button class="fcbtn btn btn-success btn-outline btn-1e waves-effect">编辑完毕2</button>
                    </div>
                </div>
                <div id="store-booter">
                    <div class="row">
                        <div class="col-sm-12">
                            <textarea >ddd</textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <button class="fcbtn btn btn-success btn-outline btn-1e waves-effect">编辑完毕3</button>
                    </div>
                </div>

            </div>
        </div>
    </div>
@endsection
@section('js')
    @parent
    <!-- icheck -->
    <script src="{{ asset('plugins/bower_components/icheck/icheck.min.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/icheck/icheck.init.js') }}"></script>
    <script src="{{ asset('js/jasny-bootstrap.js') }}"></script>
    <!-- jQuery file upload -->
    <script src="{{ asset('plugins/bower_components/dropify/dist/js/dropify.min.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/summernote/dist/summernote.min.js') }}"></script>
    <script>
        $(document).ready(function () {
            // Basic
            $('.dropify').dropify();
        });
    </script>
    <script src="{{ asset('plugins/bower_components/bootstrap-select/bootstrap-select.min.js') }}"
            type="text/javascript"></script>
    <!-- bt-switch -->
    <script src="{{ asset('plugins/bower_components/bootstrap-switch/bootstrap-switch.min.js') }}"></script>
    <script type="text/javascript">

        jQuery(document).ready(function () {

            $('.summernote').summernote({
                height: 350, // set editor height
                minHeight: null, // set minimum height of editor
                maxHeight: null, // set maximum height of editor
                focus: false, // set focus to editable area after initializing summernote$('.summernote').summernote({
                toolbar: [
                    // [groupName, [list of button]]
                    ['style', ['bold', 'italic', 'underline', 'clear']],
                    ['fontsize', ['fontsize']],
                    ['fontname', ['fontname']],
                    ['color', ['color']],
                    ['para', ['ul', 'ol', 'paragraph']],
                    ['height', ['height']],
                    ['insert', ['link', 'picture', 'video']],
                    ['view', ['fullscreen', 'codeview', 'help']]
                ],
                lang: 'zh-CN',
                // placeholder: '内容',
                dialogsFade: true,
            });

            $('.inline-editor').summernote({
                airMode: true
            });

        });

        $(".bt-switch input[type='checkbox'], .bt-switch input[type='radio']").bootstrapSwitch();
        var radioswitch = function () {
            var bt = function () {
                $(".radio-switch").on("switch-change", function () {
                    $(".radio-switch").bootstrapSwitch("toggleRadioState")
                }),
                    $(".radio-switch").on("switch-change", function () {
                        $(".radio-switch").bootstrapSwitch("toggleRadioStateAllowUncheck")
                    }),
                    $(".radio-switch").on("switch-change", function () {
                        $(".radio-switch").bootstrapSwitch("toggleRadioStateAllowUncheck", !1)
                    })
            };
            return {
                init: function () {
                    bt()
                }
            }
        }();
        $(document).ready(function () {
            radioswitch.init()
        });

        $(document).ready(function () {
            var hidden = $('#hidden').val();
            if (hidden === 'hidden') {
                toastsuccess($('#message').val());
            }
        });
        var _btn = $('.button');

        $(document).ready(function () {
            var _this = $('#post-booter');
            _this.removeClass('btn-info');
            _this.addClass('btn-default');
            $('#push-booter').hide();
            $('#store-booter').hide();
        });

        //点击按钮展示不同的页面
        _btn.on('click', '#post', function () {
            var _this = $('#post-booter');
            _this.removeClass('btn-info');
            _this.addClass('btn-default');
            _this.show();
            $('#push-booter').hide();
            $('#store-booter').hide();
        });

        _btn.on('click', '#push', function () {
            var _this = $('#push-booter');
            _this.removeClass('btn-primary');
            _this.addClass('btn-default');
            $('#post-booter').hide();
            _this.show();
            $('#store-booter').hide();
        });

        _btn.on('click', '#store', function () {
            var _this = $('#store-booter');
            _this.removeClass('btn-success');
            _this.addClass('btn-default');
            $('#post-booter').hide();
            $('#push-booter').hide();
            _this.show();
        });

        //编辑完成
        $('#push-booter').on('click', '.btn', function () {
            var nei = $('#nei').val();
            swal({
                    title: "",
                    text: "确定推送该消息吗？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/post',
                        type: 'POST',
                        data: {'nei': nei},
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });
    </script>
@endsection